export function _dateTimeFormatter2Number(date) {
  const year = date.getFullYear();
  let month = date.getMonth() + 1;
  let day = date.getDate();
  let hour = date.getHours();
  let minute = date.getMinutes();
  let second = date.getSeconds();

  month = `0${month}`.slice(-2);
  day = `0${day}`.slice(-2);
  hour = `0${hour}`.slice(-2);
  minute = `0${minute}`.slice(-2);
  return `${year}${month}${day}`;
}

export function _dateTimeFormatter(date) {
  const year = date.getFullYear();
  let month = date.getMonth() + 1;
  let day = date.getDate();
  let hour = date.getHours();
  let minute = date.getMinutes();
  let second = date.getSeconds();

  month = `0${month}`.slice(-2);
  day = `0${day}`.slice(-2);
  hour = `0${hour}`.slice(-2);
  minute = `0${minute}`.slice(-2);

  // return `${day}.${month}.${year} ${hour}:${minute}`; // by srx
  return `${year}/${month}/${day} `
}

// 时间戳转日期格式
export function formatDate(now) {
  var year = now.getFullYear();
  var month = now.getMonth() + 1;
  var date = now.getDate();
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  };
  if (date >= 0 && date <= 9) {
    date = "0" + date;
  };
  return year + "-" + month + "-" + date;
}
// 日期格式转时间戳
export function dateToMs(date) {
  return new Date(date).getTime()
}

// 获取输入日期的前三月
export function defaultThreeMonths(localdate) {// localdate is String . "2023-03-02"
  var newdate = new Date(localdate.replace(/-/g, "/"))
  newdate = newdate.setMonth(newdate.getMonth() - 3)
  var aa = new Date(newdate);
  return formatDate(aa); // 时间戳转日期格式
}

// 获取输入时间的上一年

export function getLastYear(localdate) { // localdate is String . "2023-03-02"
  var newdate = new Date(localdate.replace(/-/g, "/"))
  newdate = newdate.setFullYear(newdate.getFullYear() - 1)
  var aa = new Date(newdate);
  return formatDate(aa); // 时间戳转日期格式
}

export function getTodayLastYear() {
  var newdate = new Date();
  newdate = newdate.setFullYear(newdate.getFullYear() - 1)
  var aa = new Date(newdate);
  return aa;
  //return formatDate(aa); // 时间戳转日期格式
}

export function getFutureOneMoreYear() {
  var newdate = new Date();
  newdate = newdate.setFullYear(newdate.getFullYear() + 1)
  var aa = new Date(newdate);
  return aa;
  //return formatDate(aa); // 时间戳转日期格式
}
